#include "./query_task.h"
#include "../driver/cmd_uart.h"
#include "../service/salve_conn.h"
#include "./handler_task.h"

#if defined (BOARD_HEAT)
#include "../service/heat/config_info.h"
#endif

namespace task {

using namespace driver;
using namespace utils;
using namespace conn;
using namespace service;

#if defined (BOARD_HEAT)

static void on_get_flow(const Message &msg) {
    salveConn->response(msg, 
        configInfo->flow_count_1000ml
    );
}

#endif

static void on_ping(const Message &msg) {
    salveConn->echo(msg);
}

void QueryTask::run() {
    
    Message msg;
    for (;;) {
        m_mq.poll(msg);
        dispatch(msg);
    }
}

void QueryTask::dispatch(const Message &msg) {

    switch (msg.conn_info.req) {
        case proto::REQ_GET_TASK_INFO: on_get_task_info(msg); break;
        case proto::REQ_PING: on_ping(msg); break;

#if defined(BOARD_HEAT)
        case proto::REQ_HEAT_GET_LOW: on_get_flow(msg); break;
#endif
    }
}

void QueryTask::on_get_task_info(const Message &msg) {
//     uint8_t task_id;
//     Error err = msg.parse(task_id);
//     if (err) {
//         goto finish;
//     }
    

// finish:

    const TaskInfo &task_info = handlerTask->task_info();

    salveConn->response(msg, task_info.req, task_info.seq);
}

}
